<template>
  <div class="task-list">
    <div class="nav-bar">
      <span class="alltitle">
        <router-link to="项目列表">项目列表</router-link>>预备员工专区>
        <router-link to="/task">新手任务</router-link>>新人列表
      </span>
      <p>
		  <span class="download-button" @click="exportExcel">完成情况表导出</span>
		  <span class="download-button" @click="exportTb" style="margin-left:10px;">同步</span>
	  </p>
    </div>
    <div class="table">
      <div class="title">
        <span class="left-one">状态</span>
        <span class="left-two">姓名</span>
        <span class="left-three">操作</span>
      </div>
      <div class="list" v-for="(item, index) in currentData" :key="index">
        <span class="left-one">{{status[item.status]}}</span>
        <span class="left-two">{{item.name}}</span>
        <span class="left-three">
          <router-link class="button" :to="'/task/detail/'+item.id">评估</router-link>
        </span>
      </div>
    </div>
    <div class="page" v-if="hasData">
      <Page :total="pagetotal" :page-size="pagesize" @on-change="changePage"></Page>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentData: [],
      hasData: true,
      pagesize: 10,
      pagetotal: 100,
      //  0未上传  1未审核 2未通过 3 已通过
      status: {
        0: "未上传",
        1: "未审核",
        2: "未通过",
        3: "已通过"
      }
    };
  },
  methods: {
    changePage: function(index) {
      $.get('https://evp.51job.com/51job/api/1.0/index.php/minirs/Xsrw_information/index',{
          project_id: this.$store.getters.project_id_get,
          pageindex: index,
          pagesize: this.pagesize
      }).then(res => {
         this.currentData = res.data.data
      })
    },
    exportExcel: function() {
      window.open("https://evp.51job.com/51job/api/1.0/index.php/minirs/Xsrw_information/importExecl?project_id="+this.$store.getters.project_id_get);
    },
	loadFun: function() {
		console.log(localStorage.getItem("project_id"));
		$.get('https://evp.51job.com/51job/api/1.0/index.php/minirs/Xsrw_information/index',{
		     project_id: this.$store.getters.project_id_get?this.$store.getters.project_id_get:localStorage.getItem("project_id"),
		     pageindex: 1,
		     pagesize: this.pagesize
		 }).then(res => {
		    this.currentData = res.data.data;
		    this.pagetotal = res.data.pagecount
		     if (res.data.data.length == 0) {
		       this.hasData = false
		     }
		 })
	},
	exportTb:function(){
		
		$.get('https://evp.51job.com/51job/api/1.0/index.php/minirs/Xsrw_information/sync',{
		    project_id: this.$store.getters.project_id_get?this.$store.getters.project_id_get:localStorage.getItem("project_id"),
		}).then(res => {
		   this.loadFun();
		})
	}
  },
  created() {
	  this.loadFun();
     
  }
};
</script>

<style scoped>
.nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}

.nav-bar .download-button {
  width: 120px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  display: inline-block;
  color: white;
  background: #3091f2;
}

.table {
  width: 80%;
  margin: 50px auto 50px;
}

.table .left-one, .table .left-two {
  display: inline-block;
  width: 240px;
}

.table .title,
.table .list {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  padding: 10px 10px;
}

.table .title {
  font-weight: bold;
}

.table .list {
  border-top: 1px rgb(221, 221, 221) solid;
}

.table .list .button {
  display: inline-block;
  width: 70px;
  height: 35px;
  line-height: 35px;
  text-align: center;
  color: white;
  background: #3091f2;
}

.table .list .button:hover,
.nav-bar .download-button:hover {
  cursor: pointer;
}

.page {
  display: flex;
  justify-content: center;
}
</style>
